package dongze.com.ckdj.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;

import dongze.com.ckdj.activity.BaseActivity;
import dongze.com.ckdj.dagger.component.AppComponent;
import dongze.com.ckdj.map.MapUtil;
import dongze.com.ckdj.util.MyLog;

/**
 * Created by fanqwz on 2017/7/20.
 */

public class BaseFragment extends Fragment {
    protected MapUtil mapUtil;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MyLog.d(getClass().getSimpleName(), "onCreate: ");
        setHasOptionsMenu(true);
        mapUtil = new MapUtil(getComponent(AppComponent.class));
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onDestroy() {
        MyLog.d(getClass().getSimpleName(), "onDestroy: ");
        mapUtil.dispose();
        super.onDestroy();
    }

    public <T> T getComponent(Class<T> clazz) {
        Activity activity = getActivity();

        if (activity instanceof BaseActivity) {
            BaseActivity baseActivity = (BaseActivity) activity;
            return baseActivity.getComponent(clazz);
        }

        return null;
    }
}
